home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln1286.arc / BNCHMARK.ADA / SIEVE.ADA < prev   
Text File  |  1986-10-21  |  1KB  |  51 lines

  1. with TEXT_IO; use TEXT_IO;
  2.  
  3. procedure SIEVE is
  4.  
  5.     --
  6.     -- Sieve of Eratosthenes
  7.     --     Source available from Mark Petersen's Alpo-Net FIDO board at
  8.     --     (619) 741-3412, 300/1200/2400 8,N,1
  9.     --
  10.  
  11.  
  12.     size : constant integer := 8192;
  13.  
  14.     count : long_integer;
  15.     flags : array (0..size) of boolean;
  16.     k     : natural;
  17.     prime : natural;
  18.  
  19. begin
  20.  
  21.     --
  22.     -- Compute a table of the first n prime numbers.
  23.     --
  24.  
  25.     count := 0;
  26.  
  27.     --
  28.     -- Do it 10 times
  29.     --
  30.  
  31.     for j in 1..10 loop
  32.         for i in 0..size loop
  33.             flags(i) := TRUE;
  34.         end loop;
  35.  
  36.         for i in 0..size loop
  37.             if flags(i) then
  38.                 prime := i + i + 3;
  39.                 k := i + prime;
  40.                 while k <= size loop
  41.                     flags(k) := FALSE;
  42.                     k := k + prime;
  43.                 end loop;
  44.                 count := count + 1;
  45.             end if;
  46.         end loop;
  47.     end loop;
  48.  
  49.     put_line(long_integer'image(count) & " primes");
  50. end SIEVE;
  51.